using System;
using System.ComponentModel;
using System.Windows.Threading;

namespace GuiMongo
{
    public class NotifyingDateTime : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private DateTime _now;

        public NotifyingDateTime()
        {

            _now = DateTime.Now;

            var timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(100)};

            timer.Tick += timer_Tick;

            timer.Start();

        }

        public DateTime Now
        {

            get { return _now; }

            private set
            {

                _now = value;

                if (PropertyChanged != null)

                    PropertyChanged(this, new PropertyChangedEventArgs("Now"));

            }

        }

        void timer_Tick(object sender, EventArgs e)
        {

            Now = DateTime.Now;

        }
    }
}